package com.welink.cmp.convertor;

import com.welink.cmp.dao.metadata.dataobject.FirewallDO;
import com.welink.cmp.domain.metadata.Firewall;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 防火墙转换器
 */
public class FirewallConvertor {

    /**
     * 将 Domain 对象转换为 DataObject 对象
     *
     * @param firewall 防火墙领域对象
     * @return 防火墙数据对象
     */
    public static FirewallDO toDataObject(Firewall firewall) {
        if (firewall == null) {
            return null;
        }
        FirewallDO firewallDO = new FirewallDO();
        firewallDO.setId(firewall.getId());
        firewallDO.setAssetsId(firewall.getAssetsId());
        firewallDO.setSn(firewall.getSn());
        firewallDO.setName(firewall.getName());
        firewallDO.setVendor(firewall.getVendor());
        firewallDO.setBrand(firewall.getBrand());
        firewallDO.setModel(firewall.getModel());
        firewallDO.setUnitSize(firewall.getUnitSize());
        firewallDO.setRackNo(firewall.getRackNo());
        firewallDO.setRackUnitPosition(firewall.getRackUnitPosition());
        firewallDO.setDataCenterCode(firewall.getDataCenterCode());
        firewallDO.setExpirationTime(firewall.getExpirationTime());
        firewallDO.setLaunchedTime(firewall.getLaunchedTime());
        firewallDO.setOs(firewall.getOs());
        firewallDO.setMajorVersion(firewall.getMajorVersion());
        firewallDO.setPatchVersion(firewall.getPatchVersion());
        firewallDO.setBmcIp(firewall.getBmcIp());
        firewallDO.setIps(firewall.getIps());
        firewallDO.setSnatIps(firewall.getSnatIps());
        firewallDO.setDnatIps(firewall.getDnatIps());
        firewallDO.setBandwidth(firewall.getBandwidth());
        firewallDO.setOpsBandwidth(firewall.getOpsBandwidth());
        firewallDO.setPurchaseTime(firewall.getPurchaseTime());
        firewallDO.setStatus(firewall.getStatus());
        firewallDO.setCreateTime(firewall.getCreateTime());
        firewallDO.setUpdateTime(firewall.getUpdateTime());
        firewallDO.setCreateBy(firewall.getCreateBy());
        firewallDO.setUpdateBy(firewall.getUpdateBy());
        return firewallDO;
    }

    /**
     * 将 DataObject 对象转换为 Domain 对象
     *
     * @param firewallDO 防火墙数据对象
     * @return 防火墙领域对象
     */
    public static Firewall toDomainObject(FirewallDO firewallDO) {
        if (firewallDO == null) {
            return null;
        }
        Firewall firewall = new Firewall();
        firewall.setId(firewallDO.getId());
        firewall.setAssetsId(firewallDO.getAssetsId());
        firewall.setSn(firewallDO.getSn());
        firewall.setName(firewallDO.getName());
        firewall.setVendor(firewallDO.getVendor());
        firewall.setBrand(firewallDO.getBrand());
        firewall.setModel(firewallDO.getModel());
        firewall.setUnitSize(firewallDO.getUnitSize());
        firewall.setRackNo(firewallDO.getRackNo());
        firewall.setRackUnitPosition(firewallDO.getRackUnitPosition());
        firewall.setDataCenterCode(firewallDO.getDataCenterCode());
        firewall.setExpirationTime(firewallDO.getExpirationTime());
        firewall.setLaunchedTime(firewallDO.getLaunchedTime());
        firewall.setOs(firewallDO.getOs());
        firewall.setMajorVersion(firewallDO.getMajorVersion());
        firewall.setPatchVersion(firewallDO.getPatchVersion());
        firewall.setBmcIp(firewallDO.getBmcIp());
        firewall.setIps(firewallDO.getIps());
        firewall.setSnatIps(firewallDO.getSnatIps());
        firewall.setDnatIps(firewallDO.getDnatIps());
        firewall.setBandwidth(firewallDO.getBandwidth());
        firewall.setOpsBandwidth(firewallDO.getOpsBandwidth());
        firewall.setStatus(firewallDO.getStatus());
        firewall.setPurchaseTime(firewallDO.getPurchaseTime());
        firewall.setCreateTime(firewallDO.getCreateTime());
        firewall.setUpdateTime(firewallDO.getUpdateTime());
        firewall.setCreateBy(firewallDO.getCreateBy());
        firewall.setUpdateBy(firewallDO.getUpdateBy());
        return firewall;
    }

    /**
     * 将 Domain 对象列表转换为 DataObject 对象列表
     *
     * @param firewalls 防火墙领域对象列表
     * @return 防火墙数据对象列表
     */
    public static List<FirewallDO> toDataObjectList(List<Firewall> firewalls) {
        return firewalls.stream()
                .map(FirewallConvertor::toDataObject)
                .collect(Collectors.toList());
    }

    /**
     * 将 DataObject 对象列表转换为 Domain 对象列表
     *
     * @param firewallDOs 防火墙数据对象列表
     * @return 防火墙领域对象列表
     */
    public static List<Firewall> toDomainObjectList(List<FirewallDO> firewallDOs) {
        return firewallDOs.stream()
                .map(FirewallConvertor::toDomainObject)
                .collect(Collectors.toList());
    }
}
